# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>
#This value is here because some python package names have capital letters
#while there is a strong preference for lowercase letters in ArchLinux and
#MSYS packages.

_pyname=PyYAML
_realname=yaml
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=3.12
pkgrel=2
pkgdesc="Python bindings for YAML, using fast libYAML library (mingw-w64)"
arch=('any')
url='https://pyyaml.org/'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-libyaml")
options=('staticlibs' 'strip' '!debug')
source=("https://pyyaml.org/download/pyyaml/${_pyname}-$pkgver.tar.gz")
install=python-yaml.install
sha256sums=('592766c6303207a20efc445587778322d7f73b161bd994f227adaa341ba212ab')

prepare() {  
  cd "$srcdir"/  
  for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_pyname}-${pkgver}" "python${pver}-build-${CARCH}"
  done
}  
  
# Note that build() is sometimes skipped because it's done in 
# the packages setup.py install for simplicity if you can do so.
# but sometimes, you want to do a check before install which would
# also trigger the build.  
build() {  
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

check() {  
  for pver in {2,3}; do  
    msg "Python ${pver} test for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"  
    ${MINGW_PREFIX}/bin/python${pver} setup.py test
  done  
}

package_python3-yaml() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3" "${MINGW_PACKAGE_PREFIX}-libyaml")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/COPYING"
}

package_python2-yaml() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2" "${MINGW_PACKAGE_PREFIX}-libyaml")

  cd "${srcdir}/python2-build-${CARCH}"

  rm -f ./buildutils/include_win32/stdint.h
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/COPYING"
}


package_mingw-w64-i686-python2-yaml() {
  package_python2-yaml
}

package_mingw-w64-i686-python3-yaml() {
  package_python3-yaml
}

package_mingw-w64-x86_64-python2-yaml() {
  package_python2-yaml
}

package_mingw-w64-x86_64-python3-yaml() {
  package_python3-yaml
}
